//
//  BaseTableViewController.swift
//  mySwift
//
//  Created by 高赛 on 16/9/14.
//  Copyright © 2016年 高赛. All rights reserved.
//

import UIKit

class BaseTableViewController: UITableViewController {
    
    // 定义一个变量保存用户的当前登陆状态
    var userLogin = true
    
    var visitorView = VisitorView()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem()
        
        userLogin ? super.loadView() : setupVisitorView()
        
    }
    // MARK : -- 内部控制方法
    private func setupVisitorView(){
        // 设置未登录界面
        let customView = VisitorView()
        customView.delegate = self
        view = customView
        visitorView = customView
        
        // 设置导航条内容
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.plain, target: self, action: #selector(registerBtnWillClick))
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.plain, target: self, action: #selector(loginBtnWillClick))
        navigationController?.navigationBar.tintColor = UIColor.orange
    }
    
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
// mark  代理分离
extension BaseTableViewController: VisitorViewDelegate {
    
    // VisitorViewDelegate
    func loginBtnWillClick() {
        print("登录")
    }
    func registerBtnWillClick() {
        print("注册")
        
    }
}
